And the Java side of the docking, I use PHP decryption, key is 36 bytes, so there is no clue. I wonder if there's a generic way to convert these 36 bytes into 16 or 32 bytes? Thank you all first.
Here is the code snippet for Java:
public static String DES_KEY="36位的key";
Execution method:
DesUtil.decrypt(rs.getString(i+1),Global.DES_KEY );
Class:
public class Desutil {private final static String des = "des"; Private final static String padding= "Des/ecb/pkcs5padding";
point of communication with key to the core data des encryption, and then in the form of a password in the public communications network (such as telephone network) transmission to the end of the communication network, the data arrived at the destination, with the same key to decrypt the password data, It reproduces the core data in the form of plaintext. In this way, the security and reliability of core data (such as PIN, Mac, etc.) in the public communication network are ensured.
In Java, exa
* @paramkey Encryption key byte array the * @return the * @throwsException98 */ About Private Static byte[] Encrypt (byte[] Data,byte[] key)throwsException { - //generate a trustworthy random number source101SecureRandom sr =Newsecurerandom ();102 //Create a Deskeyspec object from the original key data103Deskeyspec DKs =NewDeskeyspec (key);104 //Create a key factory and use it to convert Deskeyspec to Secretkey obje
This article describes the PHP implementation of AES256 encryption algorithm, is a more common encryption algorithm. Share to everyone for your reference. Specifically as follows:
aes.class.php files are as follows:
The aesctr.class.php file is as follows:
Demo Example program is as follows:
Here's another way to use PHP mcrypt plus decryption:
/* AES 256 Encrypt
* @param string $ostr
* @param string $securekey
First, let's look at the code in Java that decrypts the string:Secret keyPrivate String key = "123456789012345678901234";Decryption process, the first decryption with Base64, and then 3DES for the second decryption, to get the plaintextpublic string Decryptthreedesecb (String src) throws Exception {Desedekeyspec DKs = new Desedekeyspec (key.getbytes (CharSet));Secretkeyfactory keyfactory = secretkeyfactory.getinstance ("Desede");Secretkey SecureKey =
administrator/// Public BOOLISAdmin {Get;Set; }Then write the login interface Public classLogincontroller:apicontroller { Publicloginresult Post ([frombody]loginrequest request) {Loginresult rs=NewLoginresult (); //Suppose the username is "admin" and the password is "123" if(Request. UserName = ="Admin" request. Password = ="123") { //If the user is logged on successfully, the user's identity data can be obtained. Of course, in actual development,
Export eyspec dks = new export eyspec (key) from the original key data; // create a key factory and use it to convert the export eyspec to the SecretKey object SecretKeyFactory keyFactory = SecretKeyFactory. getInstance (DES); SecretKey securekey = keyFactory. generateSecret (dks); // The Cipher object actually completes the encryption operation Cipher cipher = Cipher. getInstance (DES); // use the key to initialize the Cipher object cipher. init (Ci
{// generate a trusted random number source SecureRandom sr = new SecureRandom (); // create the export eyspec object named Export eyspec dks = new export eyspec (key) from the original key data; // create a key factory and use it to convert the export eyspec to the SecretKey object SecretKeyFactory keyFactory = SecretKeyFactory. getInstance (DES); SecretKey securekey = keyFactory. generateSecret (dks); // The Cipher object actually completes the enc
[] datasource, String password)
{
Try
{
SecureRandom random = new SecureRandom ();
DESKeySpec export ey = new DESKeySpec (password. getBytes ());
// Create a key factory and use it to convert the keyspec
SecretKeyFactory keyFactory = SecretKeyFactory. getInstance ("DES ");
SecretKey securekey = keyFactory. generateSecret (secret ey );
// The Cipher object actually completes the encryption operation
Cipher cipher = Cipher
it to convert Deskeyspec into
Secretkeyfactory keyfactory = secretkeyfactory.getinstance ("DES");
Secretkey SecureKey = Keyfactory.generatesecret (Deskey);
The Cipher object actually completes the encryption operation
Cipher Cipher = cipher.getinstance ("DES");
Initializing a Cipher object with a secret key
Cipher.init (Cipher.encrypt_mode, SecureKey, Random);
Now, get the data and encrypt it.
Form
null; base64decoder decoder = new Base64decoder (); byte[] buf = decoder.decodebuffer (data); byte[] bt = Decrypt (buf, key.getbytes ()); return New String (BT); }
/*** Description is encrypted based on the key value** @param data* @param key* Encryption key byte array* @return* @throws Exception*/private static byte[] Encrypt (byte[] data, byte[] key) throws Exception {Generate a trustworthy random number sourcesecurerandom sr = new SecureRandom ();
Create a Deskeyspec object from ra
");Secretkey SecureKey = Keyfactory.generatesecret (Deskey);The Cipher object actually completes the cryptographic operationCipher Cipher = cipher.getinstance ("des/ecb/nopadding");Initialize the Cipher object with a keyCipher.init (Cipher.encrypt_mode, SecureKey, Random);Now, get the data and encryptFormally perform cryptographic operationsreturn cipher.dofinal (data);} catch (Throwable e) {E.printstacktra
); //Create a key factory and use it to convert Deskeyspec to a Secretkey objectSecretkeyfactory keyfactory =secretkeyfactory.getinstance (DES); Secretkey SecureKey=Keyfactory.generatesecret (DKS); //The cipher object actually completes the cryptographic operationCipher Cipher =cipher.getinstance (DES); //Initialize the Cipher object with a keyCipher.init (Cipher.encrypt_mode, SecureKey, SR); //now, get the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.